package chapter06

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test16_Type
 * Package: chapter06
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 *          Date: 2023-06-23
 *          Time: 20:29
 */

//特征自身类型
object Test16_Type {
  def main(args: Array[String]): Unit = {
    val user = new RegisterUser("alice", "123456")
  }
}

//用户类
class User(val name: String, val password: String)

trait UserDao {
  //下滑表示别名 代表给自身起的名字
  //意思当前这个特征就有一个User实体
  _: User =>
  //向数据库插入数据
  def insert() = {
    println(s"insert into db: ${this.name}")
  }
}

//定义子类 注册用户
class RegisterUser(name: String, password: String) extends User(name, password) with UserDao